FROM --platform=$BUILDPLATFORM m.daocloud.io/docker.io/library/node:18.20.5 as build
ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN mkdir /peer-server
WORKDIR /peer-server
COPY package.json package-lock.json ./
RUN npm config set registry https://registry.npmmirror.com
RUN npm clean-install
COPY . ./
RUN npm run build
RUN npm run test

FROM m.daocloud.io/docker.io/library/node:18.20.5-alpine as production
RUN mkdir /peer-server
WORKDIR /peer-server
COPY package.json package-lock.json ./
RUN npm config set registry https://registry.npmmirror.com
RUN npm clean-install 
COPY --from=build /peer-server/dist/bin/peerjs.js ./
ENV PORT 9010
EXPOSE ${PORT}
ENTRYPOINT ["node", "peerjs.js"]
